import { constantRoutes, asyncRoutes } from '@/router/index'
export default {
  namespaced: true,
  state: {
    routes: [...constantRoutes]
  },
  mutations: {
    getMenuList(state, data) {
      state.routes = [...constantRoutes, ...data]
    }
  },
  actions: {
    filterRoutes(xtc, menuList) {
      const userAsyncRoutes = []
      asyncRoutes.forEach(item => {
        if (menuList.find(conter => conter.name === item.name)) {
          if (item.children && item.children.length) {
            item.children = item.children.filter(chil => menuList.find(o => o.name === chil.name))
          }
          userAsyncRoutes.push(item)
        }
      })
      // 侧边栏
      xtc.commit('getMenuList', userAsyncRoutes)
      return userAsyncRoutes
    }
  }
}
